<?php

namespace app\modules\groups\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\modules\groups\models\TreeForm;

/**
 * GroupQuery represents the model behind the search form about `app\modules\groups\models\Group`.
 */
class TreeSeach extends TreeForm
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'root', 'groupDesc', 'lft', 'rgt', 'lvl', 'name', 'source_table', 'source_table_pk'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = self::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        if (!($this->load($params) && $this->validate())) {
            return $dataProvider;
        }

        $query->andFilterWhere([
            'id' => $this->id,
            'root' => $this->root,
            'lft' => $this->lft,
        ]);
//
//        $query->andFilterWhere(['like', 'groupName', $this->groupName])
//            ->andFilterWhere(['like', 'groupCode', $this->groupCode])
//            ->andFilterWhere(['like', 'groupDesc', $this->groupDesc])
//            ->andFilterWhere(['like', 'group_mark', $this->group_mark])
//            ->andFilterWhere(['like', 'createUser', $this->createUser])
//            ->andFilterWhere(['like', 'updateUser', $this->updateUser])
//            ->andFilterWhere(['like', 'groupStr', $this->groupStr]);

        return $dataProvider;
    }
}
